import React from 'react'
import PubSub from 'pubsub-js'
import './Header.css'
export default function Header() {
  return (
    <div className="todo-header">
      <input
        type="text"
        onKeyUp={(e) => {
          const value = e.target.value.trim()
          if (!value || e.key !== 'Enter') return
          // 传递数据
          PubSub.publish('addTodo', value)
          // 清空文本框
          e.target.value = ''
        }}
      />
    </div>
  )
}
